/**
 * Label.as
 * Showtime
 * version 1.0
 * 
 * A Label component for displaying a single line of text.
 * 
 * Copyright (c) 2011 Showtime
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package showtime.framework.ui
{
	import flash.display.DisplayObjectContainer;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;

	public class Label extends UIComponent
	{
		protected var _autoSize:Boolean = true;
		protected var _text:String = null;
		
		protected var _textField:TextField = null;
		
		public function Label(parent:DisplayObjectContainer = null, xpos:Number = 0, ypos:Number = 0, text:String = "")
		{
			_text = text;
			super(parent, xpos, ypos);
		}
		
		override protected function initialize():void
		{
			super.initialize();			
			enabled = false;
		}
		
		override protected function createChildren():void
		{
			super.createChildren();
		
			_textField = new TextField();
			_textField.selectable = false;	
			
			addChild(_textField);
		}
		
		override public function updateDisplayList():void
		{
			super.updateDisplayList();
			
			_textField.text = _text;
			
			if (_autoSize)
			{
				_textField.autoSize = TextFieldAutoSize.LEFT;
				_width = _textField.textWidth;
			}
			else
			{
				_textField.autoSize = TextFieldAutoSize.NONE;
				_textField.width = _width;
			}
			
			_height = _textField.textHeight;
		}
		
		public function set text(value:String):void
		{
			_text = value;
			invalidate();
		}
				
		public function get text():String
		{
			return _text;
		}
		
		public function get autoSize():Boolean
		{
			return _autoSize;
		}
		
		public function set autoSize(value:Boolean):void
		{
			_autoSize = value;
		}
		
		public function get textField():TextField
		{
			return _textField;
		}
	}
}